function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function isMobile(mobile) {
  var searchStr = /^(1+\d{10})$/;
  if (!searchStr.test(mobile)) {
    return false;
  } else {
    return true;
  }
};

function isTel(val) {
  if (!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(val)) {
    return false;
  } else {
    return true;
  }
}
function isBank(val) {
  if (!/^([1-9]{1})(\d{14}|\d{18})$/.test(val)) {
    return false;
  } else {
    return true;
  }
}
function isEmail(email) {
  var searchStr = /^[\w\-\.\s]+@[\w\-\.\s]+$/;
  if (!searchStr.test(email)) {
    return false;
  }
  return true;
};

// function settime(that) {
//   var countdown = 60;
//   var t = setInterval(function () {
//     if (countdown === 0) {
//       that.setData({
//         mes: "获取验证码",
//         flag: true
//       })
//       clearInterval(t);
//     } else {
//       that.setData({
//         mes: countdown + '秒后重试',
//         flag: false
//       })
//       countdown--;
//     };
//   }, 1000)
// }

// 去除空格
function trim(str) {
  return str.replace(/(^\s+)|(\s+$)/g, "");
}

module.exports = {
  isMobile,
  // settime,
  trim,
  isEmail,
  isTel,
  isBank
}